<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            padding-bottom: 800px;
        }
        #app{
            border: 6px solid black;
        }
        .model-box{
            position: fixed;
            top: 0px;
            left: 0px;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.6);
        }
        
        .model-content{
            background-color: white;
            display: inline-block;
            width: 400px;
            min-height: 300px;
            box-shadow: 0 0 8px #333;
            border-radius: 6px;
            position: absolute;
            left: 50%;
            top: 10%;
            transform: translate(-50%,0);
        }
        .model-header{
            line-height: 1.8;
            border-bottom:1px solid #dedede
        }
    </style>
</head>
<body>
    <div id="app" style="transform:translate(100px,100px)">
        <h1>页面内容</h1>
        <input type="button" value="添加" @click="addModel=true">
        <input type="button" value="修改" @click="setModel=true">
        <input type="button" value="详情" @click="detailModel=true">

        <!-- 添加模态窗 -->
        <my-model title="添加" v-model="addModel"></my-model>
        <!-- 修改模态窗 -->
        <my-model title="修改" v-model="setModel"></my-model>
        <!-- 详情模态窗 -->
        <my-model title="详情" v-model="detailModel"></my-model>
    </div>
    

    <script type="text/x-template" id="model">
        <!-- 在不改变vue的语法使用情况下，让对应的标签或者组件，具有自定义的,页面展示位置的定义功能 -->
        <teleport to="body">
            <div class="model-box" v-show="modelValue" @click=" $emit('update:modelValue',false) ">
                <div class="model-content" @click.stop>
                    <div class="model-header">{{ title }}</div>
                    <div class="model-body">
                        模态(dialog)窗的内容
                        <input type="text">
                    </div>
                </div>
            </div>
        </teleport>
    </script>
    <script type="module"> 
        import { createApp } from "../../assets/vue3/vue.esm-browser.js";
        const app = createApp({
            data(){
                return {
                    addModel:false,
                    setModel:false,
                    detailModel:false,
                }
            }
        })
        
        app.component("MyModel",{
            template:"#model",
            emits:["update:modelValue"],
            props:{
                modelValue:{
                    type:Boolean,
                    default:false
                },
                title:{
                    type:String,
                    default:"标题"
                }
            }
        })
        
        app.mount("#app")
    </script>
</body>
</html>